package me.spring.cloud.components.starter.rpc.crypto.service;

import cn.hutool.crypto.asymmetric.KeyType;
import cn.hutool.crypto.asymmetric.RSA;
import java.io.InputStream;
import me.spring.cloud.common.components.rpc.crypto.service.CryptoService;

/**
 * @author luffy
 * @description: RSA
 * @date 2019-11-15 17:28
 */
public class CommonRsaCryptService extends AbstractRsaCryptService implements CryptoService {

  private RSA rsa;

  public CommonRsaCryptService(String privateKey, String publicKey) {
    this.rsa = new RSA(privateKey, publicKey);
  }

  @Override
  public String encrypt(String string) {
    return super.encryptBase64(string, KeyType.PublicKey, rsa);
  }

  @Override
  public byte[] encrypt(byte[] bytes) {
    return super.encrypt(bytes, rsa);
  }

  @Override
  public byte[] encrypt(InputStream is) {
    return super.encrypt(is, rsa);
  }

  @Override
  public String decrypt(String string) {
    return super.decryptForKey(string, KeyType.PrivateKey, rsa);
  }

  @Override
  public byte[] decrypt(byte[] bytes) {
    return super.decrypt(bytes, rsa);
  }

  @Override
  public byte[] decrypt(InputStream is) {
    return super.decrypt(is, rsa);
  }

}
